using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Terra.Core.Configuration;

/// <summary>
/// 项目配置扩展方法
/// </summary>
public static class ProjectExtensions
{
    /// <summary>
    /// 添加项目配置
    /// </summary>
    /// <param name="services">服务集合</param>
    /// <param name="configuration">配置</param>
    public static IServiceCollection AddProjectSettings(this IServiceCollection services, IConfiguration configuration)
    {
        services.Configure<ProjectSettings>(configuration.GetSection("ProjectSettings"));
        return services;
    }

    /// <summary>
    /// 获取项目名称
    /// </summary>
    public static string GetProjectName(this IConfiguration configuration)
    {
        return configuration["ProjectSettings:Name"] ?? "Terra";
    }

    /// <summary>
    /// 获取数据库表前缀
    /// </summary>
    public static string GetTablePrefix(this IConfiguration configuration)
    {
        return configuration["ProjectSettings:TablePrefix"] ?? "terra_";
    }

    /// <summary>
    /// 获取缓存键前缀
    /// </summary>
    public static string GetCacheKeyPrefix(this IConfiguration configuration)
    {
        return configuration["ProjectSettings:CacheKeyPrefix"] ?? "terra:";
    }

    /// <summary>
    /// 获取消息队列前缀
    /// </summary>
    public static string GetQueuePrefix(this IConfiguration configuration)
    {
        return configuration["ProjectSettings:QueuePrefix"] ?? "terra.";
    }
}